<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/boot.js"></script>
    <style>
    </style>
</head>

<body>
    <div id="container">
        <div id="formcontainer">
            <form class="layui-form layui-form-pane" id="editform" lay-filter="editform">
                <div class="layui-row">
                    <div class="layui-col-xs6">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">任务名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="job_name" id="job_name" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <div class="layui-form-item" pane="">
                            <label class="layui-form-label required">任务类别</label>
                            <div class="layui-input-block">
                                <input type="text" name="job_type" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required" style="width: 130px;">job类全路径</label>
                            <div class="layui-input-block" style="margin-left: 130px;">
                                <input type="text" name="job_class_path" id="job_class_path" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row cyclediv" style="display: none;">
                    <div class="layui-col-xs6">
                        <div class="layui-form-item">
                            <label class="layui-form-label required">执行间隔</label>
                            <div class="layui-input-block">
                                <input type="text" name="execute_peroid" autocomplete="off" class="layui-input number" value="1">
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <div class="layui-form-item" pane="">
                            <label class="layui-form-label required">间隔单位</label>
                            <div class="layui-input-block">
                                <input type="text" name="execute_unit" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row corndiv" style="display: none;">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item">
                            <label class="layui-form-label required" style="width: 130px;">corn表达式</label>
                            <div class="layui-input-block" style="margin-left: 130px;">
                                <input type="text" name="corn_express" autocomplete="off" class="layui-input required">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs6">
                        <div class="layui-form-item" pane="">
                            <label class="layui-form-label required">任务状态</label>
                            <div class="layui-input-block">
                                <input type="text" name="job_status" autocomplete="off" class="layui-input required" disabled>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs6">
                        <div class="layui-form-item">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-block">
                                <input type="text" name="sort_num" autocomplete="off" class="layui-input number" value="0">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row">
                    <div class="layui-col-xs12">
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label">说明</label>
                            <div class="layui-input-block">
                                <textarea type="text" name="remark" autocomplete="off" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div id="opcontainer">
            <button class="layui-btn" onclick="HandleSelect()">快速选择</button>
            <button class="layui-btn" onclick="HandleSave()">确认</button>
            <button class="layui-btn layui-btn-primary" onclick="HandleClose()">关闭</button>
        </div>
    </div>
</body>
<script>
    $(function() {
        BindRadio("job_type", "定时任务类别", 10, JobTypeChange);
        BindRadio("job_status", "定时任务状态", 20);
        BindSelect("execute_unit", "定时任务间隔单位", 10);
        BindControl();
    })

    function HandleSave() {
        SubmitForm('editform', 'system/common/job/insert', BeforeSubmit, null, function(result, status) {
            if (result.code == 0) {
                OpenSuccess('添加成功', function(params) {
                    CloseDialog();
                })
            } else {
                OpenFail(result.msg);
            }
        })
    }

    function HandleSelect() {
        OpenDialog('选择任务', 'system/job/job_quick_select.html', 900, 700, function(data) {
            if (data != null) {
                $("#job_name").val(data.job_name);
                $("#job_class_path").val(data.job_class_path);
            }
        })
    }

    function BeforeSubmit(data) {
        return true;
    }

    function HandleClose() {
        CloseDialog();
    }

    function BindControl() {
        var param = layui.form.val("editform");
        if (param.job_type == '10') {
            $(".corndiv").hide();
            $(".cyclediv").show();
        } else {
            $(".corndiv").show();
            $(".cyclediv").hide();
        }
    }

    function JobTypeChange(value) {
        BindControl();
    }
</script>

</html>